int lengthOfLastWord(char* s) {
    int n = strlen(s);
    int lastwordlen = 0;
    for (int i = n - 1; i >= 0; i--) {
        if (s[i] != ' ') {
            lastwordlen += 1;
        }
        if (s[i] == ' ' && lastwordlen != 0) {
            return lastwordlen;
        }
    }
    return lastwordlen;
}